package com.anlu.thread.t8;

public class ThreadDemo {
    private static int count = 0;

    public synchronized static void  add(){
        count++;
    }

    public static void main(String[] args){
        for (int i=0;i<20;i++){
            new Thread(new Runnable() {
                @Override
                public void run() {
                    for (int k=0;k<10000;k++){
                        add();
                    }
                }
            }).start();
        }
        while (Thread.activeCount()>2){
            Thread.yield();
        }
        System.out.println("最后的结果是:"+count);
    }
}
